

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.Face;
import com.loong.loong.hik.service.FaceService;
import groovy.util.logging.Slf4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 人脸管理
 *
 * @author jinyiang
 * @date 2023-03-28 17:17:48
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/face/face" )
@Api(value = "face", tags = "人脸管理管理")
public class FaceController {

    private final  FaceService faceService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param face 人脸管理
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_face_view')" )
    public R getFacePage(Page page, Face face) {

		return R.ok(faceService.queryFaces(page,face));

		}


    /**
     * 通过id查询人脸管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_face_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(faceService.getById(id));
    }

    /**
     * 新增人脸管理
     * @param face 人脸管理
     * @return R
     */
    @ApiOperation(value = "新增人脸管理", notes = "新增人脸管理")
    @SysLog("新增人脸管理" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_face_add')" )
    public R save(@RequestBody Face face) {
        return faceService.add(face);
    }

    /**
     * 修改人脸管理
     * @param face 人脸管理
     * @return R
     */
    @ApiOperation(value = "修改人脸管理", notes = "修改人脸管理")
    @SysLog("修改人脸管理" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_face_edit')" )
    public R updateById(@RequestBody Face face) {
        return faceService.update(face);
    }

    /**
     * 通过id删除人脸管理
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除人脸管理", notes = "通过id删除人脸管理")
    @SysLog("通过id删除人脸管理" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('hik_face_del')" )
    public R removeById(@PathVariable Integer id) {
        return faceService.remove(id);
    }


    /**
     * 导出excel 表格
     * @param face 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_face_export')" )
    public List<Face> export(Face face) {
        return faceService.list(Wrappers.query(face));
    }
}
